﻿/**
  KCAKCAK   CAKCAKC   AK      CA
 AK        KC     CA  AK    AK
CA         KC     CA  AK  KC
CA         KCAKCAKCA  AKCA
CA         KC     CA  AK  KC
 AK        KC     CA  AK    AK
  KCAKCAK  KC     CA  AK      CA

_________________________________________________________________ China ataca Kamchatka - copyright 2007(c) Ruben Sainz de la Maza
 
	@class: 	Cards
	@vertion: 	0.1
	@date:		22/11/07
				
	@language: 	ActionScript 3.0
	@author:	Ruben Sainz de la Maza
	@usage: 
		_objCards = Cards.getInstance();
			
**/

package com.conelmate.cak.board.cards
{
	
	import com.conelmate.util.Trace;
	import com.conelmate.cak.board.data.CAKdata;
	
	
	public class Cards extends Trace implements ICard
	{
		private	static	var	_INSTANCE		:Cards;				//instancia de esta clase (singleton)
		private 		var	_isFreeze		:Boolean = false;	//true:congela eventos, false:reactiva eventos
		private			var _isInited		:Boolean = false;	//false:la clase aun no ha sido iniciada

		private 		var _objCAKdata		:CAKdata;			//datos centralizados
		private 		var _objCards		:Object;			//almacena los objetos Cards		

		
//_________________________________________________________________________________ Constructor
		public function Cards(enforcer:SingletonEnforcer)
		{
			_isTrace = false;
			mTrace("#Cards# constructor");
			
			init();
		}		
		

//_________________________________________________________________________________ Public Methods

		/**
		 * Singleton.  Devuelve una instancia unica de esta clase
		 */
		public static function getInstance():Cards
		{
			if(Cards._INSTANCE == null) Cards._INSTANCE = new Cards(new SingletonEnforcer());
			return Cards._INSTANCE;
		}
		
		
		/**
		 * Inicializa la clase
		 */
		public function init():void
		{
			if(!_isInited){
				mTrace("#Cards# init");
				_isInited = true;
				
				//codigo de inicializacion
				if(!_objCards) setCards();
			}			
		}
		

		/**
		 * Destruye las instancias
		 */
		public function destroy():void
		{
			mTrace("#Cards# destroy");
			_objCards = null;
			_isInited = false;
			Cards._INSTANCE = null;
		}
		
		
		/**
		 * Congela / descongela los eventos de la clase
		 * @param   freeze 
		 */		
		public function freeze(freeze:Boolean):void
		{
			mTrace("#Cards# freeze");
			_isFreeze = freeze;
		}
		


//_________________________________________________________________________________ Private Methods
		
		/**
		 * obtener los datos de las tarjetas desde CAKdata y guardarlos localmente en _objCards
		 */		
		private function setCards():void
		{
			mTrace("#Cards# setCards");	
			
			_objCAKdata = CAKdata.getInstance();
			_objCards = _objCAKdata.objCards;			
			
			//verificar:
		//	for(var i in _objCards) trace(i+" "+_objCards[i].icon.name);

		}
		


//_________________________________________________________________________________ GETTERS
//_________________________________________________________________________________ SETTERS

	}
}

class SingletonEnforcer{}